export const getLocalStorage = (...args) => {
  const storage = {}
  args.forEach(arg => {
    storage[arg] = window.localStorage.getItem(arg) || null
  })
  return storage
}

export const setLocalStorage = data => {
  Object.keys(data).forEach(prop => {
    const el = data[prop]
    window.localStorage.setItem(prop, el)
  })
}

export const removeLocalStorage = (...args) => {
  args.forEach(arg => {
    window.localStorage.removeItem(arg)
  })
}

export const getSessionStorage = (...args) => {
  const storage = {}
  args.forEach(arg => {
    storage[arg] = window.sessionStorage.getItem(arg) || null
  })
  return storage
}
export const setSessionStorage = data => {
  Object.keys(data).forEach(prop => {
    const el = data[prop]
    window.sessionStorage.setItem(prop, el)
  })
}
export const removeSessionStorage = (...args) => {
  args.forEach(arg => {
    window.sessionStorage.removeItem(arg)
  })
}
export const isWeixinBrowser = () => {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.indexOf('micromessenger') != -1) {
      return true;
  } else {
      return false;
  }
}


export function setUserInfo(userInfo){
    // 使用示例
  if (isWeixinBrowser()) {

    return setLocalStorage(userInfo)
  } else {

    return setSessionStorage(userInfo)
  }
}

export function getUserInfo(){
  if (isWeixinBrowser()) {

    return getLocalStorage('mobile','password')
  } else {

    return getSessionStorage('mobile','password')
  }
  // return getLocalStorage('mobile','password')


}
export function delUserInfo(){
  if (isWeixinBrowser()) {

    return removeLocalStorage('mobile','password')
  } else {

    return removeSessionStorage('mobile','password')

  }

}